args = commandArgs(T)

data = vector("list", length(args))
means = vector("numeric", length(args))

for(a in seq_along(args)) {
	v = read.table(args[[a]])
	data[[a]] = v$V1 + v$V2

	print.noquote(args[[a]])
	s=summary(data[[a]])
	means[[a]] = s[["Mean"]]
	print(s)
}

xran = c(1, max(sapply(data, FUN=length)))
yran = c(0, max(range(data)))

len = length(data)
col = rainbow(len)
chr = 5:(4+len)

d = dirname(args[[1]])
f = paste(d, "bars.pdf", sep="/")

pdf(f)
print(col)
barplot(means, main=d, col=col, names=paste(basename(args),"\n", means))
dev.off()

f = paste(d, "times.pdf", sep="/")
pdf(f)
plot.new()
plot.window(xran, yran)
title(d)
axis(2, tck=1)
for(l in seq_along(data))
	lines(data[[l]], col=col[[l]], type="o", pch=chr[[l]])
legend("bottom", legend=paste(basename(args),"\n", means), fill=col, horiz=T, bty="n")

dev.off()
